package data.mapper.implementation;

import java.util.ArrayList;
import java.util.StringTokenizer;

import data.dictionary.Dictionary;
import data.mapper.Mapper;
import data.preprocessing.StringProcessor;
import data.vectors.DoubleVector;
import data.vectors.implementation.DoubleVector_Sparse_Memory;

public class MapperStringToDoubleVector implements Mapper<String, DoubleVector> {

	private Dictionary<String> dico;
	private StringProcessor sp;
	
	
	
	public MapperStringToDoubleVector(Dictionary<String> dico,
			StringProcessor sp) {
		super();
		this.dico = dico;
		this.sp = sp;
	}



	public DoubleVector map(String from) {
		DoubleVector_Sparse_Memory vec = new DoubleVector_Sparse_Memory();
		
		//String docPP = sp.map(from); // pre-processing

		StringTokenizer st;
		if(sp==null)
			st = new StringTokenizer(sp.map(from), " "); // decoupage
		else
			st = new StringTokenizer(from, " "); 
		
		
		//System.out.println(sp.map(docPP));
		
		while (st.hasMoreTokens()){
			
			int ind = -1;
			
			ind = dico.indexOf(st.nextToken());
			
			if(ind >-1)
				vec.setValue(ind, vec.getValue(ind)+1);
		
		}
		return vec;
	}

	
}
